package auctionhaus
//Authors: Paul Kleczka, Adam Backstrom

//A Listing of Bids
class Listing {

    String name
    Date endDateTime
    float startingBidPrice
    String description
    Date dateCreated
    boolean completed
    float minimumBid
    
    static belongsTo = [seller:Customer]
    Customer winner
    
    List bids
    static hasMany = [bids: Bid]

    static constraints = {
        description nullable:  true, maxSize: 255
        name maxSize: 63, blank: false
        winner nullable: true
        endDateTime validator: { end,obj->
            //this date could be only one second in the future... may be better to set a minimum further out
            return (end > new Date() || obj.completed)
        }
        startingBidPrice min: 0.01F
        completed nullable: true
    }

    public float getCurrentBid()
    {
        return bids?.last()?.amount
    }
}
